<?php
########################################################
# DMS Donations Management System v1.0                 #
# created by:  Isaac Sabas                             #
#			   Nikko Reyes							   #
#			   Miko Tiamwatt						   #
#                                                      #
# De La Salle Philippines                              #
# All Rights Reserved DLSP Copyright 2009              #
########################################################

# INFORMATION:
# dashboard_client_window.php 
# 	- this script is responsible for the handling of data for the client profile window
# 	
#	the script has two (2) modes:
#		- display - gets the data from the database using DBHandle.php class
#		- profile update processing - provides error checking and validation before submitting information to the database using DBHandle.php class
#

define('START', true);	

session_start();	
	

	#############################	
	# set error checking levels #
	#############################			
		# enable these lines when site is to be deployed #	
		ini_set('error_reporting', E_ALL);
	    ini_set('display_errors', 'On');
	    //ini_set('log_errors', 'On');
	    //ini_set('error_log', '/usr/local/apache/logs/error_log');

	#############################
	# include some needed files #
	#############################
		$absRoot = '../../';
		include($absRoot . 'lib/PEAR/PEAR/Sigma.php');	
		include($absRoot . 'lib/XAJAX/xajax_core/xajax.inc.php');
		include($absRoot . 'src/ClientHandle.php');

	##################################	
	# instantiate predifined classes #
	##################################
	$template = new HTML_Template_Sigma($absRoot . 'templates', 'templates-cache');												
		//$xajax = new xajax();				

	###########################################################	
	# register all functions to be handled by XAJAX framework #
	###########################################################
		/*function echo_ajaxtest($text) {
			$objResponse = new xajaxResponse();

			$objResponse->addAssign("_ajaxtest.response","innerHTML", $text);				

			return $objResponse;
		}

		$xajax->registerFunction("echo_ajaxtest");
		*/
	##################
	# page variables #
	##################	
		$page_title = 'De La Salle University | Donations Management System ';
		$css = 'css/client.css';
		//$xajax_directives = $xajax->getJavascriptConfig() . $xajax->getJavascriptInclude('lib/XAJAX/');										

	###########################
	# load template to buffer #
	###########################
		$template->loadTemplateFile('windows/client_profile.html');	

	#########################################
	# index page template processor section #
	#########################################																							

	########################	
	# login logout section #		
	########################

	############################			
	# privelage filter section #
	############################

		#########################					
		# page processor engine #			
		#########################


	###########################	
	# load template variables #
	###########################
	$id = $_GET["client_id"];

	$client = new ClientHandle();

	$ProfileArray=$client->getClientProfile($id);
	$AddressesArray=$client->getAddresses($id);

	$AddressArray=$AddressesArray[0];
	$CompanyAddressArray=$AddressesArray[2];
	
	$PhonesArray=$client->getPhoneNumbers($id);
	$HomePhoneArray=$PhonesArray[0];
	$CompanyPhoneArray=$PhonesArray[0];
	$MobilesArray=$client->getMobileNumbers($id);
	$MobileArray=$MobilesArray[0];

	
	//Type
		$ClientType="Referred";
	//Name
		$LastName=$ProfileArray["client_lastname"];
		$FirstName=$ProfileArray["client_firstname"];
		$MiddleName=$ProfileArray["client_middlename"];
		$ClientName=$LastName . ", " . $FirstName . " " . $MiddleName;
	//Gender
		$ClientGender=$ProfileArray["client_gender"];
	//Birthday
		$BirthMonth="April";
		$BirthDay="2";
		$BirthYear="1990";
		$ClientBirthDate=$BirthMonth . " " . $BirthDay . ", " . $BirthYear;
	//Address
		$HouseNumber="151";
		$HouseStreet=$AddressArray["address_street"];
		$HouseMunicipality=$AddressArray["address_municipality"];
		$HouseCity=$AddressArray["address_city"];
		$HouseProvince=$AddressArray["address_province"];
		$HouseZipCode=$AddressArray["address_zipcode"];
		$HouseCountry=$AddressArray["address_country"];
		$ClientAddress=$HouseNumber . " " . $HouseStreet . " " . $HouseMunicipality . " " . $HouseCity . " " . $HouseProvince . " " . $HouseZipCode . " " . $HouseCountry;
	//Mobile"
		$MobileCountryCode=$MobileArray["mobile_countrycode"];
		$Provider=$MobileArray["mobile_provider"];
		$MobileNum=$MobileArray["mobile_number"];
		$ClientMobileNumber=$MobileCountryCode . "" . $Provider . "" . $MobileNum;
	//HomeNumber
	$HomeCountryCode=$HomePhoneArray["phone_countrycode"];
	$HomeAreaCode=$HomePhoneArray["phone_areacode"];
	$HomeNumber=$HomePhoneArray["phone_number"];
	$ClientHomeNumber=$HomeCountryCode . "" . $HomeAreaCode . "" . $HomeNumber;
	//CompanyNumber
	$CompanyCountryCode=$CompanyPhoneArray["phone_countrycode"];
	$CompanyAreaCode=$CompanyPhoneArray["phone_areacode"];
	$CompanyNumber=$CompanyPhoneArray["phone_number"];
	$ClientCompanyNumber=$CompanyCountryCode . "" . $CompanyAreaCode . "" . $CompanyNumber;
	//EMail
	$ClientEMail=$ProfileArray["client_email"];
	//School
	$ClientSchool=$ProfileArray["client_school"];
	//Course
	$ClientCourse=$ProfileArray["client_coursename"];
	//CourseCode
	$ClientCourseCode=$ProfileArray["client_coursecode"];
	//YearGraduated
	$ClientYearGraduated=$ProfileArray["client_yeargraduated"];
	//Batch
	$ClientBatch=$ProfileArray["client_batch"];
	//Company
	$ClientCompany=$ProfileArray["client_company"];
	//Position
	$ClientPosition=$ProfileArray["client_position"];
	//Company Address
	$CompanyNumber="20th floor";
	$CompanyStreet=$CompanyAddressArray["address_street"];
	$CompanyMunicipality=$CompanyAddressArray["address_municipality"];
	$CompanyCity=$CompanyAddressArray["address_city"];
	$CompanyProvince=$CompanyAddressArray["address_province"];
	$CompanyZipCode=$CompanyAddressArray["address_zipcode"];
	$CompanyCountry=$CompanyAddressArray["address_country"];
	$ClientCompanyAddress=$CompanyNumber . " " . $CompanyStreet . " " . $CompanyMunicipality . " " . $CompanyCity . " " . $CompanyProvince . " " . $CompanyZipCode . " " . $CompanyCountry;
	//TotalDonation
	$Donation= $ProfileArray["client_commulative_donation_amount"];
	$ClientTotalDonation="P " . $Donation;
	//Alumni
	$ClientAlumni=$ProfileArray["client_alumni"];
	//Deceased
	$ClientDeceased=$ProfileArray["client_deceased"];
	$DeceaseMonth="April";
	$DeceaseDay="2";
	$DeceaseYear="2090";
	$ClientDeceasedDate=$DeceaseMonth . " " . $DeceaseDay . ", " . $DeceaseYear;

	##########################	
	# set template variables #
	##########################	


		$template->setVariable('PAGE_TITLE', $page_title);	
		$template->setVariable('STYLE', $css);
		$template->setVariable('absRoot', $absRoot);
		
		//Client Profile
		$template->setVariable('CLIENTID', $id);
		$template->setVariable('CLIENTTYPE', $ClientType);
		$template->setVariable('CLIENTNAME', $ClientName);
		$template->setVariable('CLIENTGENDER', $ClientGender);
		$template->setVariable('CLIENTBIRTHDATE', $ClientBirthDate);
		$template->setVariable('CLIENTADDRESS', $ClientAddress);
		$template->setVariable('CLIENTMOBILENUMBER', $ClientMobileNumber);
		$template->setVariable('CLIENTHOMENUMBER', $ClientHomeNumber);
		$template->setVariable('CLIENTCOMPANYNUMBER', $ClientCompanyNumber);
		$template->setVariable('CLIENTEMAIL', $ClientEMail);
		$template->setVariable('CLIENTSCHOOL', $ClientSchool);
		$template->setVariable('CLIENTCOURSE', $ClientCourse);
		$template->setVariable('CLIENTCOURSECODE', $ClientCourseCode);
		$template->setVariable('CLIENTYEARGRADUATED', $ClientYearGraduated);
		$template->setVariable('CLIENTBATCH', $ClientBatch);
		$template->setVariable('CLIENTCOMPANY', $ClientCompany);
		$template->setVariable('CLIENTPOSITION', $ClientPosition);
		$template->setVariable('CLIENTCOMPANYADDRESS', $ClientCompanyAddress);
		$template->setVariable('CLIENTTOTALDONATION', $ClientTotalDonation);
	if($ClientAlumni==1)
		$template->setVariable('CLIENTALUMNI', "checked");
	if($ClientDeceased==1)	
	{
		$template->setVariable('CLIENTDECEASED', "checked");
		$template->setVariable('CLIENTDECEASEDDATE', $ClientDeceasedDate);
	}

		//$template->setVariable('DASHBOARD_NOTIFICATION1_DATA', 'Made Calls');
		//$template->setVariable('XAJAX_INIT', $xajax_directives);

	#############################	
	# render the index template #
	#############################
		//$xajax->processRequests();	
		$template->show();		
	?>	